package tt.lab.pmbok.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import tt.lab.pmbok.model.Area;

public class AreaDaoHibernate  implements AreaDao {
	@Resource(name = "sessionFactory")
	private SessionFactory sessionFactory;
	
	private Session getSession(){
		return sessionFactory.getCurrentSession();
	}
	

	public List<Area> loadById(int id) {
		Query query;
		String hql;
		if (id > 0) {
			hql = "from Area where id = :id";
//			System.out.println(hql);
			query = getSession().createQuery(hql);
			query.setInteger("id", id);
		} else {
			hql = "from "+Area.class.getName();
//			System.out.println(hql);
			query = getSession().createQuery(hql);
		}

		List<Area> list = (List<Area>) query.list();
		return list;
	}


}
